package com.evaluationSystem.controller;

import com.evaluationSystem.config.R;
import com.evaluationSystem.entity.WeightList;
import com.evaluationSystem.entity.vo.WeightDataVo;
import com.evaluationSystem.service.WeightListService;
import com.evaluationSystem.util.AssertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName WeightController
 * @Description 权重控制器
 * @Author yinzhenxing
 * @Date 2023/1/4 17:55
 **/
@RestController
@RequestMapping("/weightList")
public class WeightListController {
    @Autowired
    private WeightListService weightListService;

    @GetMapping(value = "/getList")
    private R<List<WeightList>> getList() {
        return R.success(weightListService.getList());
    }

    @PostMapping(value = "/save")
    public R<String> save(@RequestBody WeightList weight) {
        weightListService.save(weight);
        return R.success("新增成功");
    }

    @PutMapping(value = "/edit")
    public R<String> edit(@RequestBody WeightList weight) {
        weightListService.edit(weight);
        return R.success("修改成功");
    }

    @GetMapping(value = "/getInfo")
    private R<List<WeightDataVo>> getInfo(@RequestParam String questionId) {
        return R.success(weightListService.getInfo(questionId));
    }

    @PostMapping(value = "/saveWeight")
    public R<String> saveWeight(@RequestBody Map<String, Object> map) {
        weightListService.saveWeight(map);
        return R.success("新增成功");
    }

    @PutMapping(value = "/editWeight")
    public R<String> editWeight(@RequestBody Map<String, Object> map) {
        weightListService.editWeight(map);
        return R.success("修改成功");
    }

    @DeleteMapping(value = "/delWeight")
    public R<String> delWeight(@RequestBody Map<String, Object> map) {
        List dataIdList = (List) map.get("dataIdList");

        AssertUtils.isListEmpty(dataIdList, "dataIdList");

        weightListService.delWeight(map);
        return R.success("删除成功");
    }

}
